package com.mmy.dao.oa;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.mmy.domain.oa.MaterialIn;

public interface MaterialInRepository extends JpaRepository<MaterialIn, Integer> {

	/*
	 * 获取最大值id
	 */
	@Query(value = "select MAX(iInID) from tMaterialIn", nativeQuery = true)
	Object getMaxInID();

	/*
	 * 查询全部
	 */
	@Query(value = "select * from tMaterialIn , tMaterialBase where tMaterialBase.iMaterialID = tMaterialIn.iMaterialID", nativeQuery = true)
	List<MaterialIn> findAll();

	/*
	 * 根据id删除
	 */
	@Transactional
	@Modifying
	@Query(value = "delete from tMaterialIn where tMaterialIn.iInID in (:lstInID)", nativeQuery = true)
	void delMaterialIn(@Param("lstInID") List<Integer> lstInID);

	/*
	 * 根据id查找
	 */
	@Query(value = "select *  from tMaterialIn where iInID = :iInID", nativeQuery = true)
	MaterialIn findByInID(@Param("iInID") int iInID);


	/*
	 * 新增id
	 */
	@Transactional
	@Modifying
	@Query(value = "INSERT INTO tMaterialIn(iInID, iMaterialID, iNumber, dSumPrice, iUserID, dDate, dCreateDate, cCreator, dModifyDate, cReviser, cMemo, cSpare1, cSpare2, cSpare3, cSpare4, cSpare5) VALUES (:inID, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)", nativeQuery = true)
	void save(@Param("inID") int inID);

}
